<?php

class PrintComponent extends BlueprintComponent {
	
	
	function parse(&$element, $value, $maxLetters = false) {
		if ($keeptag === 'false') $keeptag = false;
		$doc = $element->document;
		
		if ($maxLetters) {
			if ($maxLetters < 0) { // a negative value will cut off mid-word at the positive length
				$maxLetters = abs($maxLetters) - 3;
				$value = "strlen($value) < $maxLetters ? $value : substr($value, 0, $maxLetters) . '...'";
			} else { // a positive value will cut off at the closest word break
				$maxLetters -= 3;
				$value = "strlen($value) < $maxLetters ? $value : substr($value, 0, strrpos(substr($value, 0, $maxLetters), ' ')) . '...'";
			}
		}
		
		$element->childNodes = array($doc->createPHPTextNode($value));
	}
}
?>